package
{
	
	
	import com.reintroducing.sound.SoundManager;
	
	import control.KeyboardCtrl;
	
	import data.Map;
	
	import element.Person;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.ui.Keyboard;
	
	import view.GameView;
	
	[SWF(width=800, height=640, backgroundColor = 0x336699)]
	public class Main extends Sprite
	{
		private var gameView:GameView;
		private var user:Person;
		private var userCtrl:KeyboardCtrl;
		private var npc:Person;
		private var npcCtrl:KeyboardCtrl;
		
		public function Main()
		{
			inits();
		}
		
		private function inits():void
		{
			// 初始化地图之后才可以访问Map.data, Map.col, Map.row等值
			// 如果不指定，那么使用Map0
			Map.level = 0;
			
			//添加游戏视图
			gameView = new GameView();
			gameView.x = 100;
			gameView.y = 60;
			addChild(gameView);
			
			//添加控制模块
			userCtrl = new KeyboardCtrl(Keyboard.UP,Keyboard.DOWN,Keyboard.LEFT,
				                        Keyboard.RIGHT,Keyboard.SPACE);
			addChild(userCtrl);
			
			//添加游戏主角
			user = new Person(new HumanCls(), userCtrl);
			userCtrl.startKeyboardListen();
			gameView.addPerson(0, 0, user);
			
			//添加NPC角色
			npc = new Person(new HumanCls(), null);
			gameView.addPerson(Map.row - 1, Map.col - 1, npc);
			
			addSound();
		}
		/**
		 * 添加背景音乐素材
		 * 
		 */		
		private function addSound():void
		{
			SoundManager.getInstance().addExternalSound("assets/village_BGM.mp3","BGM");
			SoundManager.getInstance().playSound("BGM");
		}
	}
}
